﻿namespace SanguoSharp.Server
{
    /// <summary>
    /// 响应决斗或者南蛮出杀
    /// </summary>
    public sealed class ThrowKillResponseHandler : ResponseHandler
    {
        IResultHandler handler;

        public ThrowKillResponseHandler(Player requested, Player causedBy, IResultHandler handler)
            : base(RequestType.ThrowKill, requested, causedBy)
        {
            this.handler = handler;
        }
        public ThrowKillResponseHandler(Player requested, Player causedBy)
            : this(requested, causedBy, null)
        {
        }

        protected override void OnRespondCard(Card card)
        {
            if (card.Owner != RequestedPlayer)
                throw new BadCardException();

            if (!RequestedPlayer.IsBang(card))
                throw new BadCardException();

            if (card.Type != CardType.杀)
                Game.GameTable.PlayerRespondWithCard(card, CardType.杀);
            else
                Game.GameTable.PlayerRespondWithCard(card);

            if (handler != null)
                handler.OnResult(true);
            End();
        }
        protected override void OnRespondNoAction()
        {
            RequestedPlayer.ModifyLifePoints(-1, CausedBy);
            if (handler != null)
                handler.OnResult(false);
            End();
        }
    }
}

